from flask import Blueprint, current_app, make_response
from flask_wtf import csrf


htmls_bp = Blueprint("html", __name__)


@htmls_bp.route("/<html(r'.*'):filename>")
def get_html(filename):
    if not filename:
        filename = "html/index.html"
    elif filename != "favicon.ico":
        filename = "html/" + filename
    csrf_token = csrf.generate_csrf()
    resp = make_response(current_app.send_static_file(filename))
    resp.set_cookie("csrf_token", csrf_token)
    return resp
